package com.tengol.demo.design.pattern.creational.builder.version2;

/**
 * 简化版本的构建者模式
 * 使用静态内部类+链式调用方式实现。
 *
 * @author dongrui
 * @date 2019/03/01
 */
public class CourseV2 {
    private String courseName;
    private String coursePPT;
    private String courseVideo;
    private String courseArticle;
    private String courseQa;

    private CourseV2(CourseBuilderV2 courseBuilderV2) {
        this.courseName = courseBuilderV2.courseName;
        this.coursePPT = courseBuilderV2.coursePPT;
        this.courseVideo = courseBuilderV2.courseVideo;
        this.courseArticle = courseBuilderV2.courseArticle;
        this.courseQa = courseBuilderV2.courseQa;
    }

    @Override
    public String toString() {
        return "CourseV2{" +
                "courseName='" + courseName + '\'' +
                ", coursePPT='" + coursePPT + '\'' +
                ", courseVideo='" + courseVideo + '\'' +
                ", courseArticle='" + courseArticle + '\'' +
                ", courseQa='" + courseQa + '\'' +
                '}';
    }

    /**
     * 根据业务需求选择是否提供该静态方法
     */
//    public static CourseBuilderV2 newCourseBuilder(){
//        return new CourseBuilderV2();
//    }

    public static class CourseBuilderV2 {
        private String courseName;
        private String coursePPT;
        private String courseVideo;
        private String courseArticle;
        private String courseQa;

        public CourseBuilderV2 setCourseName(String courseName) {
            this.courseName = courseName;
            return this;
        }

        public CourseBuilderV2 setCoursePPT(String coursePPT) {
            this.coursePPT = coursePPT;
            return this;
        }

        public CourseBuilderV2 setCourseVideo(String courseVideo) {
            this.courseVideo = courseVideo;
            return this;
        }

        public CourseBuilderV2 setCourseArticle(String courseArticle) {
            this.courseArticle = courseArticle;
            return this;
        }

        public CourseBuilderV2 setCourseQa(String courseQa) {
            this.courseQa = courseQa;
            return this;
        }

        public CourseV2 build(){
            return new CourseV2(this);
        }
    }
}

